package ucadminlogic

import (
	"context"
	"github.com/zeromicro/go-zero/core/logx"
	"navi-mumbai/app/rpc/model/pg/usercenter"
	"navi-mumbai/app/rpc/usercenter/internal/svc"
	"navi-mumbai/app/rpc/usercenter/pb"
	"navi-mumbai/common/xerr"
)

type CreateUserInviteConfigLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewCreateUserInviteConfigLogic(ctx context.Context, svcCtx *svc.ServiceContext) *CreateUserInviteConfigLogic {
	return &CreateUserInviteConfigLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

// 创建邀请设置
func (l *CreateUserInviteConfigLogic) CreateUserInviteConfig(in *pb.CreateUserInviteConfigReq) (*pb.CreateUserInviteConfigResp, error) {
	uf := usercenter.UserInviteConfig{
		SuperiorLevel:          in.SuperiorLevel,
		ReturnRatio:            in.ReturnRatio,
		ReturnNewRegisterMoney: in.ReturnNewRegisterMoney,
		RechargeLimit:          in.RechargeLimit,
		RechargeReturnMoney:    in.RechargeReturnMoney,
	}
	l.Logger.Infof("CreateUserInviteConfig. uf : %+v", uf)
	_, err := l.svcCtx.UserInviteConfigModel.Insert(l.ctx, &uf)
	if err != nil {
		return nil, xerr.NewGrpcErrCodeMsg(xerr.DbError, err.Error())
	}
	return &pb.CreateUserInviteConfigResp{}, nil
}
